import { getUserInfo } from '@/services';

export default {
    state: {
        userName: 'yejiang1015',
        authority: 1
    },

    effects: {
        *fetchUserInfo({ data }, { call, put }) {
            const response = yield call(getUserInfo, data);
            yield put({ type: 'setUserInfo', data: response.data.data });
        },
        *updateUserInfo({ data }, { call, put }) {
            yield put({ type: 'setUserInfo', data });
        }
    },

    reducers: {
        setUserInfo({ state }, { data }) {
            const { userName, authority } = data;
            return {
                ...state,
                ...data
            };
        }
    }
};
